package com.example.demo.service;

import java.util.concurrent.locks.ReentrantLock;

import org.springframework.stereotype.Service;

@Service
public class PaymentService {
    private int synchronizedCount = 0;
    private int reentrantLockCount = 0;
    private final ReentrantLock lock = new ReentrantLock();

    // 使用 synchronized 实现同步
    public synchronized void synchronizedIncrement() {
        synchronizedCount++;
        System.out.println("synchronizedCount: " + synchronizedCount);
    }

    // 使用 ReentrantLock 实现同步
    public void reentrantLockIncrement() {
        lock.lock();
        try {
            reentrantLockCount++;
            System.out.println("reentrantLockCount: " + reentrantLockCount);
        } finally {
            lock.unlock();
        }
    }
}    